<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseLink {

	protected $m_intLinkId;
	protected $m_intMid;
	protected $m_intUserId;
	protected $m_intLevelId;
	protected $m_strDummy;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getLinkId(){
		return $this->m_intLinkId;
	}

	public function getMid(){
		return $this->m_intMid;
	}

	public function getUserId(){
		return $this->m_intUserId;
	}

	public function getLevelId(){
		return $this->m_intLevelId;
	}

	public function getDummy(){
		return $this->m_strDummy;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setLinkId( $LinkId ){
		$this->m_intLinkId = $LinkId;
	}

	public function setMid( $Mid ){
		$this->m_intMid = $Mid;
	}

	public function setUserId( $UserId ){
		$this->m_intUserId = $UserId;
	}

	public function setLevelId( $LevelId ){
		$this->m_intLevelId = $LevelId;
	}

	public function setDummy( $Dummy ){
		$this->m_strDummy = $Dummy;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into LINK (link_id, mid, user_id, level_id, dummy) values (" . $this->getLinkId() . ", " . $this->getMid() . ", " . $this->getUserId() . ", " . $this->getLevelId() . ", '" . $this->getDummy() . "')");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE LINK set  mid= " . $this->getMid() . ", user_id= " . $this->getUserId() . ", level_id= " . $this->getLevelId() . ", dummy= '" . $this->getDummy() . "' where link_id =" . $this->getLink_id() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM link WHERE link_id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'link'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}